import 'package:dio/dio.dart';
import 'package:caose/caose.dart' show LoadingDialogMixin;
import 'BaseModel.dart';

class ErrorInterceptor extends InterceptorsWrapper {
  @override
  Future<dynamic> onError(DioError err) async {
    // TODO: implement onError
    return Response(
        request: err.request,
        statusCode: 200,
        data: {"status": 10086, "msg": "请求失败"});
  }
}

class ErrorToastInterceptor extends InterceptorsWrapper
    with LoadingDialogMixin {
  @override
  Future onResponse(Response response) async {
    try {
      var model = BaseModel.fromMap(response.data);
      var status = model.status;
      if (status == 1) return response;
      if (status == -1) return response;
      if (status == -3) return response;
      dismissAllToasts();
      showToast(model.msg.toString());
    } catch (e) {}
//    return super.onResponse(response);
  }
}
